package com.gcb.swing.copy.beta1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

public class DataHandler {

	public static List array2List(Object[] objs){
		List list = new ArrayList();
		for (Object object : objs) {
			list.add(object);
		}
		return list;
	}
	
	public static void copy2(String src, String desc) throws Exception{
		
		File srcFile = new File(src);
		File descFile = new File(desc);
		if(descFile.isDirectory()){
			descFile = new File(desc, srcFile.getName());
		}
		long srcFileLength = srcFile.length();
		int bbNum = (int) ((srcFileLength / 10240000) + 1);
		long st = System.currentTimeMillis();
		FileInputStream fis = new FileInputStream(srcFile);
		FileOutputStream fos = new FileOutputStream(descFile);
		FileChannel fic = fis.getChannel();
		FileChannel foc = fos.getChannel();
		for (int i = 0; i < bbNum; i++) {
			ByteBuffer dst = ByteBuffer.allocate(10240000);
			fic.read(dst);
			dst.flip();
			foc.write(dst);
		}
		System.out.println("总共花费时间：" + (System.currentTimeMillis() - st) + "毫秒！");
		fic.close();
		foc.close();
	}
	
}
